package ml.iray.bean;

/**
 * Created by boot on 12/13/15.
 * <p>
 * 此抽象类实现了<see cref="ISequence"/>接口，
 * 所有的实体类都直接或间接的继承自此此抽象类
 * <p>
 * <p>
 * 该类重写了Object的GetHashCode()方法
 * 同时也重写了Object的Equals(Object obj)方法
 */
public class AbstractSequence<T> implements ISequence<T> {
    //  实体的系统内部编号
    private T id;

    public T getId() {
        return id;
    }

    public void setId(T newId) {
        if (newId != null)
            this.id = newId;
    }

    @Override
    public int hashCode() {
        int hash = 1;
        hash = hash * 31 + (id == null ? 0 : id.hashCode());
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof AbstractSequence) {
            AbstractSequence seq = (AbstractSequence) obj;
            return seq.getId().equals(id);
        }
        return false;
    }
}
